from datetime import date

from django.db.models import Q
from django.shortcuts import render

# Create your views here
from django.views import View
from users.models import Employees, Department


class Request(View):
    def post(self, request):
        Employees.objects.create(
            empno=8888,
            ename='pyhton',
            job="DEV",
            mgr=7902,
            hiredate=date(1991, 1, 1),
            sal=10000,
            dept=20,
        )

    def delete(self, request):
        e = Employees.objects.get(empno=8888)
        e.delete()

    def put(self, request):
        e = Employees.objects.get(empno=8888)
        e.sal = 6000
        e.save()

    def get(self, request):
        Employees.objects.filter(ename__contains='A')
        Employees.objects.filter(empno__in=[7369, 7900, 7902])
        Employees.objects.filter(hiredate__gt=date(1982, 9, 1))
        Employees.objects.filter(Q(job__exact='CLERK') | Q(sal__gt=1500))
        Employees.objects.filter(dept__exact=20).get(min('sal'))
        Employees.objects.filter(dept__exact=30).order_by(-'sal')
        de30 = Department.objects.filter(deptno__exact=30)
